#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>



int main(int argc,char** argv){
	int sockfd;
	sockfd=socket(AF_INET,SOCK_STREAM,0);

	struct sockaddr_in addr;
	bzero(&addr,sizeof(struct sockaddr_in));
#ifndef LINUX
	addr.sin_len=sizeof(struct sockaddr_in);
#endif
	addr.sin_port=htons(80);
	addr.sin_addr.s_addr=inet_addr(argv[1]);
	addr.sin_family=AF_INET;

	int ret;
	ret=connect(sockfd,(struct sockaddr*)&addr,sizeof(struct sockaddr_in));
	if(ret!=0){
		perror("connect error");
		exit(1);
	}	
	printf("sockfd:%d,ret:%d\n",sockfd,ret);
	char buffer[256];
	int n=snprintf(buffer,256,"GET /\n\n");
	buffer[n]='\n';
	write(sockfd,buffer,n);

	bzero(buffer,256);
	while((n=read(sockfd,buffer,256))>0){
		buffer[n]='\0';
		write(1,buffer,n);
		bzero(buffer,n);
	}

	close(sockfd);
}
